﻿var playersGrid = $("#players-grid");
var playersGridPager = $("#players-pager");

playersGrid.jqGrid({
    url: '/Players/Page/',
    datatype: 'json',
    mtype: 'POST',
    pager: playersGridPager,
    height: 232,
    width: "100%",
    scrollOffset: 1,
    rowNum: 10,
    sortname: 'Name',
    colModel: [
        { label: 'Pos.', name: 'Position', width: 60, align: "center" },
        { label: 'Jugador', name: 'Name', width: 150 },
        { label: 'Equipo', name: 'TeamName', width: 90 },
        { label: 'Precio', name: 'Price', width: 80, align: "right", sorttype: "int", formatter: 'integer' },
        { label: ' ', name: 'Id', width: 80, sortable: false, formatter: buyLinkFormatter, align: "center" }
    ]
});

function buyLinkFormatter(playerId, options) {
    return "<a href='javascript:onBuyClick(" + options.rowId + ");'>Comprar</a>";
}

function onBuyClick(rowId) {
    var player = playersGrid.getRowData(rowId);
    buyPlayer(player);
}